
from xml.dom.minidom import parse
import xml.dom.minidom

import riftsRace
import riftsOptions
from rollDice import diceRoller

global options
CLASSTree = xml.dom.minidom.parse("classList.xml")
collection = CLASSTree.documentElement

classes = collection.getElementsByTagName("class")

class CharacterClass:
    def __init__(self, tree):
        self.Name = tree.getAttribute("name")
        self.Type = tree.getAttribute("type").split(",")
        self.Psionics = tree.getAttribute("psionics")
        self.Magic = tree.getAttribute("magic")
        self.Cybernetics = tree.getAttribute("cybernetics")
        self.Bonus = tree.getAttribute("bonus")
        self.RaceLimit = tree.getElementsByTagName("race")[0].childNodes[0].data.split(",")
        self.AlignmentLimit = tree.getElementsByTagName("alignment")[0].childNodes[0].data
        self.AttributeReqs = tree.getElementsByTagName("attributes")
        self.Skills = tree.getElementsByTagName("skills")
        self.HtoH = tree.getElementsByTagName("HtoH")
        self.RelatedSkills = tree.getElementsByTagName("relatedSkills")
        self.SecondarySkills = tree.getElementsByTagName("secondSkills")
        self.Description = tree.getElementsByTagName("description")[0].childNodes[0].data

    def isRaceAllowed(self,race):
        if "ANY" in self.RaceLimit:
            print "ANY"
            return 1
        if race in self.RaceLimit:
            print "TRUE"
            return 1
        else:
            print "FALSE"
            return 0

    def getRaceList(self,races):
        raceList = {"":""}
        RaceList = races.copy()
        del RaceList[""]
        for race in RaceList.keys():
            if self.isRaceAllowed(race):
                print "ADDING " + race
                raceList.update({race:RaceList[race]})
        return raceList

def getClassList():
    dictOfClasses = {"":""}
    for item in classes:
        char = CharacterClass(item)
        dictOfClasses.update({char.Name:char})
    return dictOfClasses

if __name__ == "__main__":
    dictOfClasses = {"":""}
    for item in classes:
        char = CharacterClass(item)
        dictOfClasses.update({char.Name:char})
